package com.vercon.moensmart.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.vercon.moensmart.R
import com.vercon.moensmart.adapter.base.BaseAdapter
import com.vercon.moensmart.databinding.ItemCardIndicatorLayoutBinding

class IndicatorAdapter(context: Context?) : BaseAdapter<ItemCardIndicatorLayoutBinding, Int?>(context) {
    private var index = 0
    fun setCurrentIndex(index: Int) {
        this.index = index
        notifyDataSetChanged()
    }

    override fun baseViewHolder(parent: ViewGroup): BaseViewHolder {
        val binding: ItemCardIndicatorLayoutBinding = ItemCardIndicatorLayoutBinding.inflate(LayoutInflater.from(context), parent, false)
        return ViewHolder(binding)
    }

    override fun bindItemView(viewHolder: BaseViewHolder?, position: Int, t: Int?, total: Int) {
        if (position == index) {
            viewHolder?.mBinding?.igStar?.setImageResource(R.mipmap.ic_card_indicator_selected)
        } else {
            viewHolder?.mBinding?.igStar?.setImageResource(R.mipmap.ic_card_indicator_no_select)
        }
    }

    inner class ViewHolder(itemBinding: ItemCardIndicatorLayoutBinding) : BaseViewHolder(itemBinding)
}